package com.kudian.common.utils;

import org.apache.log4j.Logger;

import java.text.ParseException;

/**
 * Created by apple on 16/7/16.
 */
public class NumberUtils {

    private static final Logger logger = Logger.getLogger(NumberUtils.class);

    public static double toDouble(String str) {
        java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMinimumFractionDigits(0);
        nf.setMaximumFractionDigits(6);
        double ret = 0;
        try {
            if (StringUtils.isBlank(str)) {
                return ret;
            }
            ret = nf.parse(str).doubleValue();
        } catch (ParseException e) {
            // e.printStackTrace();
            logger.error("toDouble==>");
            logger.error(e);
        }
        return ret;
    }

    public static String toString(Double d) {
        if (d == null) {
            return "";
        }
        return d.toString();
    }

    public static void main(String[] args) {
        System.out.println(toDouble("1"));
    }
}
